﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NoMvvm.TinyIoC;
using NoMvvm.TDD;
using Wizard.ViewModels;

namespace NoMvvm.UnitTests
{
    /// <summary>
    /// This is a test using the "Wizard" project for testing Mocking with NoMvvm.TDD
    /// </summary>
    [TestClass]
    public class WizardTest
    {
        public WizardTest() 
        {
            var container = new TinyIoCContainer();
            var adapter = new Adapter(container);

            adapter.AddView("Main", typeof(Blob), typeof(MainViewModel));
            adapter.AddView("First", typeof(Blob), typeof(FirstViewModel));
            adapter.AddView("Second", typeof(Blob), typeof(SecondViewModel));
            adapter.AddView("Third", typeof(Blob), typeof(ThirdViewModel));
            adapter.AddView("Fourth", typeof(Blob), typeof(FourthViewModel));
            adapter.AddView("Popup", typeof(Blob), typeof(PopupViewModel));
            
            Runtime
                .Initialize()
                .SetupTinyIoC(adapter)
                .Start("Main");
        }

        [TestMethod]
        public void Start()
        {
            dynamic main = IoC.GetViewModel("Main");

            Assert.IsInstanceOfType(main, typeof(MainViewModel));
            Assert.IsInstanceOfType(main.Child, typeof(FirstViewModel));
            Assert.IsTrue(main.CanNext);
            Assert.IsFalse(main.CanPrevious);
        }

        [TestMethod]
        public void Next_Whole_Way()
        {
            dynamic main = IoC.GetViewModel("Main");

            main.Next();
            main.Next();
            main.Next();

            Assert.IsInstanceOfType(main, typeof(MainViewModel));
            Assert.IsInstanceOfType(main.Child, typeof(FourthViewModel));
            Assert.IsFalse(main.CanNext);
            Assert.IsTrue(main.CanPrevious);
        }

        [TestMethod]
        public void Popup()
        {
            dynamic fourth = IoC.GetViewModel("Fourth");

            Assert.IsInstanceOfType(fourth, typeof(FourthViewModel));

            fourth.Popup(); //Just check there is no exception
        }
    }
}
